package org.ezplatform.office.meeting.notice.web.rest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.ezplatform.core.common.WebUser;
import org.ezplatform.core.service.BaseService;
import org.ezplatform.core.web.controller.BaseController;
import org.ezplatform.core.web.util.WebUtils;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.dingisv.util.OperationResultDing;
import org.ezplatform.office.meeting.notice.entity.NoticeInfo;
import org.ezplatform.office.meeting.notice.service.NoticeInfoService;
import org.ezplatform.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/api/m/office/meeting/notice")
public class NoticeInfoWebApiMobileController extends BaseController<NoticeInfo, String> {

	private final static Logger LOGGER = LoggerFactory.getLogger(NoticeInfoWebApiMobileController.class);
	
	@Autowired
	private NoticeInfoService service;
	
	@Autowired
	private NoticeInfoService noticeInfoService;

	@Override
	protected BaseService<NoticeInfo, String> getEntityService() {
		return service;
	}

	/**
	 * 
	 * @Title: prepareModel
	 * @Description: 初始化数据
	 * @param request
	 * @param model
	 * @param id
	 * @return void
	 * @throws
	 */
	@ModelAttribute
	public void prepareModel(HttpServletRequest request, Model model,
			@RequestParam(value = "id", required = false) String id) {
		super.initPrepareModel(request, model, id);
	}
	
    @RequestMapping(value = "/invitedHistory", method = RequestMethod.GET)
    @ResponseBody
    public OperationResultDing getInvitedHistory(@RequestParam("applyRecordId") String applyRecordId,HttpServletRequest request) {
    	WebUser user = WebUtils.getCurrentUser();
    	String userId=user.getUserId();
		String corpId = user.getCorpId();
    	Map<String,Object> paramMap= new HashMap<String,Object>();
    	paramMap.put("corpId", corpId);
    	paramMap.put("inviter", userId);
    	paramMap.put("applyRecordId", applyRecordId);
    	Integer currentPageNum=1,pageSizeNum=10,startLimitNum=0;
    	String sql="select n.notice_User_Id noticeUserId,su.user_name userName from oa_meeting_notice_info n inner join sys_user su on n.apply_Record_Id=:applyRecordId and su.id=n.notice_User_Id and inviter=:inviter and n.corp_Id=:corpId and type=1";
    	String currentPage=request.getParameter("currentPage");
    	String pageSize=request.getParameter("pageSize");
    	if(StringUtils.isNotEmpty(currentPage)){
            currentPageNum = Integer.valueOf(currentPage);
        }
        if(StringUtils.isNotEmpty(pageSize)){
            pageSizeNum = Integer.valueOf(pageSize);
        }
        startLimitNum= (currentPageNum-1) * pageSizeNum;
    	List<Map> returnList=noticeInfoService.findByListNativeQuery(sql, null,paramMap,startLimitNum,pageSizeNum);
        Map<String,Object> reMap=new HashMap<>();
        reMap.put("data", returnList);
        reMap.put("currentPage", Integer.valueOf(currentPage));
    	
        return OperationResultDing.buildSuccessResult(reMap);
    }
	
	
	
}
